package com.lizongbo.seotijian.rules.whois.domainhandlers;

import java.io.IOException;

import com.lizongbo.seotijian.rules.whois.DomainHandler;
import com.lizongbo.seotijian.rules.whois.WhoisClient;
import com.lizongbo.seotijian.util.HttpUtil;

public class FMDomainHandler implements DomainHandler {
	@Override
	public String getTld() {
		return ".fm";
	}

	@Override
	public String getWhoisInfo(String domain) {
		String url = "http://www.dot.fm/query_whois.cfm?domain="
				+ domain.substring(0, domain.lastIndexOf("."))
				+ "&tld=fm&x=27&y=10";
		String txt = "";
		try {
			txt = WhoisClient.trimEmptyLine(WhoisClient.html2txt(HttpUtil
					.httpGet(url)));
			String f = "dotFM Whois Server Version";
			int beginIndex = txt.indexOf(f);
			if (beginIndex >= 0) {
				int endIndex = txt.indexOf(f, beginIndex + f.length());
				if (endIndex > beginIndex) {
					txt = txt.substring(beginIndex, endIndex);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return (txt);
	}
}